<template>
	<view>
		<view class="search-box">
			<my-search @click="gotoSearch"></my-search>
		</view>
		<!-- 轮播图区域 -->
		<swiper class="swiper" indicator-dots="true" autoplay="true" interval="2000">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<navigator :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航区域 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item, i) in navList" :key="i" @click="navClickHandler(item)">
				<image :src="item.image_src" class="nav-img"></image>
			</view>
		</view>
		<!-- 楼层区域 -->
		<view class="floor-list">
			<!-- 楼层标题区域 -->
			<view class="floor-title" v-for="(item,i) in floorlist" :key="i">
				<image :src="item.floor_title.image_src"></image>
				<view class="floor-produt">
					<!-- 左边大图 -->
					<view class="produt-left">
						<navigator :url="item.product_list[0].url">
							<image :src="item.product_list[0].image_src"
								:style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
						</navigator>
					</view>
					<!--右边小图 -->
					<view class="produt-right">
						<view v-for="(p,s) in item.product_list" :key="s" v-if="s!==0">
							<navigator :url="p.url">
								<image :src="p.image_src" :style="{width:p.image_width+'rpx'}" mode="widthFix"></image>
							</navigator>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 轮播图的数据列表，默认为空数组      
				swiperList: [],
				// 楼层的数据列表
				floorlist: [],
				// 分类导航的数据列表
				navList: [],

			};
		},
		onLoad() {
			// 在小程序页面刚加载的时候，调用获取轮播图数据的方法   
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {

			async getSwiperList() {
				const res = await uni.$http.get('swiperimg')
				if (res.statusCode !== 200) {
					return uni.$showMsg()
				}
				this.swiperList = res.data;
			},

			async getNavList() {
				const res = await uni.$http.get('indexCate')
				if (res.statusCode !== 200) {
					return uni.$showMsg()
				}
				this.navList = res.data;
			},
			navClickHandler(item) {
				if (item.name == '分类') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			async getFloorList() {
				const res = await uni.$http.get('floorlist')

				if (res.statusCode !== 200) {
					return uni.$showMsg()
				}

				//处理图片跳转路径
				res.data.forEach(list => {
					list.product_list.forEach(item => {
						item.url = '/subpkg/goods_list/goods_list?' + item.navigator_url.split("?")[1]
					})
				})
				this.floorlist = res.data
			},
			gotoSearch(){
				uni.navigateTo({
					url: '/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="less">
	.search-box {
		position: sticky;
		top: 0;
		z-index: 999;
	}
	.swiper {
		height: calc(100vw*(366/750));

		swiper-item {
			width: 100%;
			height: 100%;

			navigator {
				width: 100%;
				height: 100%;

				image {
					width: 100%;
					height: 100%;
				}
			}

		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		width: 100%;
		height: 140rpx;
		margin: 20rpx 0;

		image {
			width: 128rpx;
			height: 100%;
		}
	}

	.floor-list {
		width: 100%;
		margin-top: 50rpx;

		.floor-title {
			width: 100%;
			display: flex;
			flex-direction: column;
			margin-top: 40rpx;

			image {

				height: 60rpx;
				width: 100%;
			}

			.floor-produt {
				width: 100%;
				display: flex;
				padding-left: 10rpx;

				// flex-direction: row;
				.produt-right {
					display: flex;
					flex-wrap: wrap;
					justify-content: space-around;
				}
			}
		}

	}
</style>
